<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Test libmacrame - Core</title>
    <link rel="stylesheet" href="common.css" type="text/css">

    <script type="text/javascript" src="common.js"></script>
    <script type="text/javascript" src="../src/core.js"></script>

    <script type="text/javascript"><!--
/*
 * This function tests if the main libmacrame function properly finds elements 
 * in the page. We do not test many CSS selectors, because the implementation is 
 * largely dependant on the querySelectorAll() method which is available 
 * natively in the most modern browsers (2009-02-26).
 */
tests.core_match = function () {
  $t.output('Testing $("#test-id") ...');

  var elem = $('#test-id');
  if (elem) {
    elem.className = 'success';
    $t.output('Element found.');
  } else {
    $t.report_error("#test-id not found.");
  }

  $t.output('Testing $(".test-class") ...');

  elem = $('.test-class');
  if (elem && elem[0]) {
    elem[0].className = 'success';
    $t.output('Element found.');
  } else {
    $t.report_error(".test-class not found.");
  }

  $t.output('Testing $("p > span") ...');

  elem = $('p > span');
  if (elem && elem[0]) {
    elem[0].className = 'success';
    $t.output('Element found.');
  } else {
    $t.report_error('"p > span" not found.');
  }
};

/*
 * We simply test for the existance of the $.browser object, and we output it, 
 * so the tester can see the results.
 */
tests.core_browsers = function () {
  if (window.navigator && window.navigator.userAgent) {
    console.log(navigator.userAgent);
  }

  var b = $.browser;
  if (!b) {
    return "$.browser is not available.";
  }

  $t.output('Browser: ' + b.name +
      ' version ' + b.version +
      ' running on ' + b.os);

  console.log('$.browser object', $.browser);
};

/*
 * We check if the $.extend static method works as expected.
 */
tests.core_extend = function () {
  var obj1 = {
    'a' : 'aa1',
    'b' : 'bb1'
  };

  var obj2 = {
    'a' : 'aa2',
    'c' : 'cc2'
  };

  var obj3 = {};

  $.extend(obj3, obj1);

  $t.check_cond(obj3.a, obj1.a, '===');
  $t.check_cond(obj3.b, obj1.b, '===');

  obj3.extend = $.extend;

  // test a different method of extending the object.
  obj3.extend(obj2);

  $t.check_cond(obj3.a, obj1.a, '===');
  $t.check_cond(obj3.b, obj1.b, '===');
  $t.check_cond(obj3.c, obj2.c, '===');

  var obj4 = {
    'a' : 'aa4',
    'd' : 'dd4'};

  // if the first argument is a boolean, it tells the extend method to overwrite 
  // any object property.
  obj3.extend(true, obj4);

  $t.check_cond(obj3.a, obj4.a, '===');
  $t.check_cond(obj3.b, obj1.b, '===');
  $t.check_cond(obj3.c, obj2.c, '===');
  $t.check_cond(obj3.d, obj4.d, '===');
};

    // --></script>
  </head>
  <body>

    <p id="test-id" class="failed">Test <code>$("#id")</code>.</p>

    <p class="test-class failed">Test <code>$(".class")</code>.</p>

    <p>Test <span class="failed">querySelector</span>.</p>

  </body>
  <!-- vim:set spell spl=en fo=tcroqwanl1 tw=80 ts=2 sw=2 sts=2 sta et ai cin ff=unix: -->
</html>
